CC = gcc
CFLAGS = -Wall -O -g
LFLAGS = -lSDL -lSDL_image -lSDL_ttf -lSDL_mixer -lm

SHELL = /bin/sh
SUBDIRS = client common game renderer scripter server tools ui zhinput

TARGET = Fire

SOUCE_FILES = $(wildcard *.c)
OBJS = $(patsubst %.c, %.o, $(SOUCE_FILES))
LIBS = $(patsubst %, %.a, $(SUBDIRS))

%.o : %.c %.h
	$(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@

$(TARGET): $(OBJS) $(LIBS)
	$(CC) $(OBJS) $(LIBS) -o $@ $(INCLUDE) $(LFLAGS)

$(LIBS): 
	@ for subdir in $(SUBDIRS); do \
		(cd $$subdir && $(MAKE)); \
		done

.PHONY:clean
clean:
	$(RM) $(OBJS) $(LIBS)
	@ for subdir in $(SUBDIRS); do \
		(cd $$subdir && $(MAKE) clean); \
		done
